Skip to content

Conversation

@petercrocker
Copy link
Contributor

@petercrocker petercrocker commented Aug 7, 2025

Fix for opsmill/infrahub#6989

Summary by CodeRabbit

  • New Features
    • Repository configuration file is now automatically discovered, supporting both .infrahub.yml and .infrahub.yaml extensions.
    • Enhanced error messages for missing configuration files, indicating both supported extensions.
  • Bug Fixes
    • Improved fallback logic to locate alternate config file extensions if the specified file is missing.
  • Documentation
    • Updated help messages and comments for clarity and typo corrections.

@coderabbitai
Copy link

coderabbitai bot commented Aug 7, 2025

Walkthrough

The changes introduce dynamic discovery of the repository configuration file by implementing functions to locate .infrahub.yml or .infrahub.yaml files, preferring .infrahub.yml when both exist. This logic replaces previous static path usage across CLI commands, generators, and pytest plugins, with updated error handling and messaging for missing configuration files.

Changes

Cohort / File(s) Change Summary
Repository Config Discovery Logic
infrahub_sdk/ctl/repository.py, infrahub_sdk/pytest_plugin/utils.py
Added find_repository_config_file to locate .infrahub.yml or .infrahub.yaml, preferring .infrahub.yml. Enhanced config loading functions to fallback to alternate extension if the primary config file is missing.
CLI and Generator Config Loading
infrahub_sdk/ctl/check.py, infrahub_sdk/ctl/cli_commands.py, infrahub_sdk/ctl/generator.py
Updated to use dynamic config file discovery via find_repository_config_file() instead of static path constants. Adjusted error messages and minor comment typo fix.
Config Constants and Docstring
infrahub_sdk/ctl/config.py
Added INFRAHUB_REPO_CONFIG_FILE_ALT for .infrahub.yaml and fixed a docstring typo.
Pytest Plugin Config Handling
infrahub_sdk/pytest_plugin/plugin.py
Changed CLI option default for config file to None, updated help text, and implemented dynamic config file discovery in session start logic. Adjusted to use find_repository_config_file() when no CLI argument is provided.

Sequence Diagram(s)

sequenceDiagram
    participant CLI/Plugin/Generator
    participant find_repository_config_file
    participant get/load_repository_config

    CLI/Plugin/Generator->>find_repository_config_file: Locate config file (.infrahub.yml/.yaml)
    find_repository_config_file-->>CLI/Plugin/Generator: Return config file path
    CLI/Plugin/Generator->>get/load_repository_config: Load config from located path
    get/load_repository_config-->>CLI/Plugin/Generator: Parsed repository config
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7a95813 and 1f2fc2b.

📒 Files selected for processing (4)
  • infrahub_sdk/ctl/check.py (2 hunks)
  • infrahub_sdk/ctl/cli_commands.py (5 hunks)
  • infrahub_sdk/ctl/generator.py (2 hunks)
  • infrahub_sdk/pytest_plugin/utils.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • infrahub_sdk/ctl/generator.py
  • infrahub_sdk/ctl/cli_commands.py
  • infrahub_sdk/ctl/check.py
  • infrahub_sdk/pytest_plugin/utils.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: unit-tests (3.11)
  • GitHub Check: integration-tests-latest-infrahub
  • GitHub Check: unit-tests (3.12)
  • GitHub Check: unit-tests (3.13)
  • GitHub Check: unit-tests (3.10)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch pmc-yaml-yml

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary or Summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Aug 7, 2025

Deploying infrahub-sdk-python with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1f2fc2b
Status: ✅  Deploy successful!
Preview URL: https://ed0480f8.infrahub-sdk-python.pages.dev
Branch Preview URL: https://pmc-yaml-yml.infrahub-sdk-python.pages.dev

View logs

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🔭 Outside diff range comments (2)
infrahub_sdk/ctl/cli_commands.py (1)

23-23: Remove unused import.

The pipeline indicates that the config import is no longer used since static path references were replaced with dynamic discovery.

-from ..ctl import config
infrahub_sdk/pytest_plugin/utils.py (1)

1-1: Add missing future annotations import.

The pipeline failure indicates that PEP 604 union syntax (Path | None) requires the future annotations import.

+from __future__ import annotations
+
 from pathlib import Path
🧹 Nitpick comments (1)
infrahub_sdk/ctl/repository.py (1)

27-52: Well-implemented function with potential code duplication concern.

The function logic is correct and well-documented:

  • Properly searches for both .infrahub.yml and .infrahub.yaml
  • Sensibly prefers .yml extension when both exist
  • Includes comprehensive docstring with type hints

However, this appears to be identical to find_repository_config_file in infrahub_sdk/pytest_plugin/utils.py. Consider consolidating these duplicate implementations into a shared utility module to maintain DRY principles.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0cde3c6 and 7a95813.

📒 Files selected for processing (7)
  • infrahub_sdk/ctl/check.py (2 hunks)
  • infrahub_sdk/ctl/cli_commands.py (5 hunks)
  • infrahub_sdk/ctl/config.py (2 hunks)
  • infrahub_sdk/ctl/generator.py (2 hunks)
  • infrahub_sdk/ctl/repository.py (1 hunks)
  • infrahub_sdk/pytest_plugin/plugin.py (3 hunks)
  • infrahub_sdk/pytest_plugin/utils.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
infrahub_sdk/pytest_plugin/plugin.py (1)
infrahub_sdk/pytest_plugin/utils.py (2)
  • find_repository_config_file (9-33)
  • load_repository_config (36-57)
infrahub_sdk/ctl/repository.py (2)
infrahub_sdk/pytest_plugin/utils.py (1)
  • find_repository_config_file (9-33)
infrahub_sdk/schema/repository.py (1)
  • InfrahubRepositoryConfig (174-259)
🪛 GitHub Actions: CI
infrahub_sdk/ctl/cli_commands.py

[error] 23-23: Ruff: ..ctl.config imported but unused (F401). Remove unused import.

infrahub_sdk/ctl/generator.py

[error] 9-9: Ruff: ..ctl.config imported but unused (F401). Remove unused import.

infrahub_sdk/ctl/check.py

[error] 14-14: Ruff: ..ctl.config imported but unused (F401). Remove unused import.

infrahub_sdk/pytest_plugin/utils.py

[error] 9-9: Ruff: Missing from __future__ import annotations, but uses PEP 604 union (FA102). Add from __future__ import annotations.

🔇 Additional comments (17)
infrahub_sdk/ctl/config.py (2)

15-15: LGTM!

Good addition of the alternate config file constant to support both .yml and .yaml extensions.


73-73: LGTM!

Nice catch fixing the typo in the docstring from "ValidationErorr" to "ValidationError".

infrahub_sdk/ctl/generator.py (2)

11-11: LGTM!

Good addition of the find_repository_config_file import to support dynamic config file discovery.


29-29: LGTM!

Excellent improvement replacing the static config file path with dynamic discovery. This enables support for both .infrahub.yml and .infrahub.yaml extensions.

infrahub_sdk/ctl/check.py (2)

17-17: LGTM!

Good addition of find_repository_config_file import for dynamic config discovery.


62-62: LGTM!

Excellent change replacing the static config path with dynamic discovery to support both config file extensions.

infrahub_sdk/ctl/cli_commands.py (5)

33-33: LGTM!

Good addition of find_repository_config_file import to enable dynamic config discovery.


263-263: LGTM!

Excellent improvement replacing the static config path with dynamic discovery in the render command.


313-313: LGTM!

Excellent improvement replacing the static config path with dynamic discovery in the transform command.


273-273: LGTM!

Good improvement making the error message generic by removing the hardcoded config filename reference.


472-472: LGTM!

Nice catch fixing the typo in the comment from "planel" to "panel".

infrahub_sdk/pytest_plugin/utils.py (2)

9-34: LGTM!

Well-implemented function for dynamic config file discovery. The logic correctly prefers .yml over .yaml when both exist, and the error handling approach of returning the .yml path for consistent error messages is thoughtful.


37-47: LGTM!

Excellent fallback logic enhancement. The bidirectional fallback between .yml and .yaml extensions provides robust config file discovery while maintaining backward compatibility.

infrahub_sdk/pytest_plugin/plugin.py (3)

12-12: LGTM!

The import addition of find_repository_config_file is necessary for the new dynamic config file discovery functionality.


21-23: LGTM!

The changes correctly implement dynamic config file discovery:

  • Setting default=None enables the new logic to automatically find the config file
  • The updated help text accurately describes support for both .infrahub.yml and .infrahub.yaml extensions

66-69: LGTM!

The conditional logic correctly implements dynamic config file discovery:

  • Preserves existing behavior when --infrahub-repo-config is explicitly provided
  • Uses find_repository_config_file() for automatic discovery when no option is given
  • Maintains backward compatibility while adding support for both .yml and .yaml extensions
infrahub_sdk/ctl/repository.py (1)

55-65: LGTM! Enhanced fallback logic and error messaging.

The changes provide useful enhancements:

  • Fallback logic (lines 55-65): Automatically tries alternate extensions when the specified config file doesn't exist, improving compatibility
  • Improved error message (line 69): Clearly indicates that both .infrahub.yml and .infrahub.yaml extensions were checked

This maintains backward compatibility while making the system more resilient to different naming conventions.

Also applies to: 69-69

@codecov
Copy link

codecov bot commented Aug 7, 2025

Codecov Report

❌ Patch coverage is 41.50943% with 31 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
infrahub_sdk/ctl/repository.py 25.00% 12 Missing and 3 partials ⚠️
infrahub_sdk/pytest_plugin/utils.py 30.00% 10 Missing and 4 partials ⚠️
infrahub_sdk/ctl/check.py 50.00% 1 Missing ⚠️
infrahub_sdk/ctl/cli_commands.py 75.00% 1 Missing ⚠️
@@                 Coverage Diff                  @@
##           infrahub-develop     #490      +/-   ##
====================================================
- Coverage             76.24%   75.52%   -0.72%     
====================================================
  Files                   100      100              
  Lines                  9032     8881     -151     
  Branches               1731     1748      +17     
====================================================
- Hits                   6886     6707     -179     
- Misses                 1670     1691      +21     
- Partials                476      483       +7     
Flag Coverage Δ
integration-tests 34.61% <30.18%> (-1.45%) ⬇️
python-3.10 48.08% <33.96%> (-1.21%) ⬇️
python-3.11 48.08% <33.96%> (-1.21%) ⬇️
python-3.12 48.03% <33.96%> (-1.23%) ⬇️
python-3.13 48.03% <33.96%> (-1.21%) ⬇️
python-3.9 46.71% <22.64%> (-1.27%) ⬇️
python-filler-3.12 25.09% <20.75%> (+0.51%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
infrahub_sdk/ctl/config.py 65.38% <100.00%> (+0.67%) ⬆️
infrahub_sdk/ctl/generator.py 50.90% <100.00%> (-0.88%) ⬇️
infrahub_sdk/pytest_plugin/plugin.py 85.10% <100.00%> (+0.66%) ⬆️
infrahub_sdk/ctl/check.py 26.44% <50.00%> (-0.61%) ⬇️
infrahub_sdk/ctl/cli_commands.py 69.00% <75.00%> (-0.13%) ⬇️
infrahub_sdk/pytest_plugin/utils.py 45.45% <30.00%> (-23.78%) ⬇️
infrahub_sdk/ctl/repository.py 70.08% <25.00%> (-8.49%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@petercrocker
Copy link
Contributor Author

Related: opsmill/infrahub#6990

@FragmentedPacket
Copy link
Contributor

Do we need to update these as well?

@petercrocker
Copy link
Contributor Author

Do we need to update these as well?

Already done here: opsmill/infrahub#6990

@petercrocker petercrocker requested a review from a team August 8, 2025 13:26
@gmazoyer
Copy link
Contributor

gmazoyer commented Aug 8, 2025

This PR should target the infrahub-develop branch, because opsmill/infrahub#6990 got merged in develop in the infrahub repo.

@petercrocker petercrocker changed the base branch from develop to infrahub-develop August 10, 2025 11:00
@petercrocker
Copy link
Contributor Author

This PR should target the infrahub-develop branch, because opsmill/infrahub#6990 got merged in develop in the infrahub repo.

Had to do a separate PR since this was already merged: #492

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants